// import './index.scss';
import XHeader from 'vux/src/components/x-header/index.vue'
import Tab from 'vux/src/components/tab/tab.vue'
import TabItem from 'vux/src/components/tab/tab-item.vue'
import Swiper from 'vux/src/components/swiper/swiper.vue'
import SwiperItem from 'vux/src/components/swiper/swiper-item.vue'
import XButton from 'vux/src/components/x-button/index.vue'
import Flexbox from 'vux/src/components/flexbox/flexbox.vue'
import FlexboxItem from 'vux/src/components/flexbox/flexbox-item.vue'
import XProgress from 'vux/src/components/x-progress/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Cell from 'vux/src/components/cell/index.vue'
import Checker from 'vux/src/components/checker/checker.vue'
import CheckerItem from 'vux/src/components/checker/checker-item.vue'
import XInput from 'vux/src/components/x-input/index.vue'
import XTextarea from 'vux/src/components/x-textarea/index.vue'
import Checklist from 'vux/src/components/checklist/index.vue'

import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
// import Http from "../../common/http";

export default {
  name: 'Project',
  components: { XHeader, Tab, TabItem, Swiper, SwiperItem, XButton, Flexbox, FlexboxItem, XProgress, Group, Cell, Checker, CheckerItem, XInput, XTextarea, Checklist },
  data () {
    return {
      index: 0,
      // 信息反馈是否有红点  为''的时候没有  为' '的时候有
      isXinxi: ' ',
      percent1: 60,
      show: false,
      demo: 0.01,
      isM: '进行中',
      userId: '',
      eventType: '',
      fankui_btn_text: '我要资助',
      item: 'item',
      textMoney: '',
      checkOK: true,
      isA: true,
      threshold: 50,
      minmovingdistance: 30,
      // 项目id
      event_id: '',
      // 显示哪一个模块
      witchShow: 'xiangqing',
      pageNoOther: 1,
      pageNoJuankuan: 1,
      pageSize: 5,
      eventAll: {},
      eventOther: [],
      eventJuankuan: [],
      lookMore: '查看更多',
      lookMoreJuankuans: '查看更多',
      leaveMessage: [],
      pageNoLeave: 1,
      isVolunteer: false,
    }
  },
  mounted () {
    this.userId = window.sessionStorage.getItem('userId')
    this.event_id = this.$route.query.event_id
    this.$emit('ifOpenid', this.$route.path,this.event_id)
    http.post(CONSTANT.BIUNIQUE_VIEW, {biunique_id: this.event_id}, (res) => {
      if (res.code == 200) {
        this.eventAll = res.obj
        this.$emit('ShareAppMessage', this.eventAll.theme, '【亲青筹】' + this.eventAll.sketch, 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=8&event_id=' + this.event_id, this.imageUrl.imageUrl + this.eventAll.picture)
        if (this.eventAll.status == 1) {
          this.isM = '进行中'
        } else if (this.eventAll.status == 3) {
          this.isM = '即将开放'
        }
        if (this.$route.query.choice == 'feedback') {
          this.witchShow = 'fankui'
          if (this.eventAll.status == 1) {
            this.fankui_btn_text = '再次资助'
          }
          this.index = 3
        }
        if (this.eventAll.feedBack == '') {
          this.isXinxi = ''
        } else {
          this.isXinxi = ' '
        }
        this.leaverMessage()
      }
    })
  },
  methods: {
    jiedui () {
      this.witchShow = 'jilu'
      if (this.eventJuankuan.length < 1) {
        this.OtherJuankuans();
      }
    },
    goDonateListDetails (id, hid) {
      this.$router.push({path: '/donateListDetails', query: {id: id, hid: hid}})
    },
    wantJuank () {
      this.$router.push({path: '/oneToOneMore',query:{event_id:this.event_id}})
    },
    leaverMessage () {
      // console.log(this.pageNoLeave)
      http.post(CONSTANT.LEAVE_MESSAGE, {biunique_id: this.event_id, pageNo: this.pageNoLeave, pageSize: this.pageSize}, (res) => {
        // console.log('liuyan', res)
        if (res.code == 200) {
          if (res.errmsg == '没有更多的留言') {
            if (this.pageNoLeave > 1) {
              this.pageNoLeave--
              alert('没有更多的留言了！')
            }
            return
          }
          if (this.pageNoLeave == 1) {
            this.leaveMessage = res.list
          } else {
            this.leaveMessage = this.leaveMessage.concat(res.list)
          }
        }
      })
    },
    moreLeaverMessage () {
      this.pageNoLeave++
      this.leaverMessage()
    },
    moreOtherProjects () {
      // 查看更多该单位项目
      this.pageNoOther++;
      this.OtherProjects()
    },
    moreOtherJuankuans () {
      // 查看更多捐款
      this.pageNoJuankuan++;
      this.OtherJuankuans()
    },
    OtherJuankuans () {
      // 捐款记录
      http.post(CONSTANT.BIUNIQUE_DONATE, {
        biunique_id: this.event_id,
        pageNo: this.pageNoJuankuan,
        pageSize: this.pageSize
      }, (res) => {
        console.log('juankuan', res)
        if (res.errmsg == '没有更多的捐款') {
          if (this.pageNoJuankuan > 1) {
            this.pageNoJuankuan--
          }
          this.lookMoreJuankuans = '没有更多的结对记录了'
          return
        } else if (res.errmsg == '') {
          for (var i = 0; i < res.list.length; i++) {
            var names = res.list[i].studentName
            names = names.split('')  // 将a字符串转换成数组
            names.splice(1, 1, '*') // 将1这个位置的字符，替换成'xxxxx'. 用的是原生js的splice方法。
            names = names.join('')  // 将数组转换成字符串。  完成。
            res.list[i].studentName = names
          }
          if (this.pageNoJuankuan == 1) {
            this.eventJuankuan = res.list
          } else {
            this.eventJuankuan = this.eventJuankuan.concat(res.list)
          }
        }
      })
    },
    comeBack () {
      window.history.go(-1)
    },
    goHello() {
      this.$router.push({path: '/Hello'})
    }
  }
}
